/**
 * Created by HiWin10 on 2016/8/4.
 */

(function() {
    'use strict';

    var m= angular
        .module('app.speclist', ['getdatamodule','chart.js']);
    m.controller('SpecListController',SpecListController);
    m.config(['ChartJsProvider', function (ChartJsProvider) {
        // Configure all charts
        ChartJsProvider.setOptions({
            colors : [ '#803690', '#00ADF9', '#DCDCDC', '#46BFBD', '#FDB45C', '#949FB1', '#4D5360'] ,
            responsive: true,
            scale:{

            },

            title: {
                display: true,
                text: '专业报道情况',
                fullWidth:true,
                fontSize:24,
                fontColor:"#666",
                fontStyle:'bold'

            },
            legend: {
                display: true,
                labels: {
                    fontColor: 'rgb(255, 99, 132)',
                    position:'bottom'
                }
            }

        });
    }])
    SpecListController.$inject=['$scope','getdataservice','$filter'];
    function SpecListController($scope,getdataservice,$filter) {
        $scope.getexcel=baseurl+"/Excel/GetSpeExcel";
        $scope.table=true;
        $scope.isLoading=false;
        var collections=[];
        $scope.filterdept="";
        $scope.filtername="";
        $scope.search=function () {
            $scope.data=[[],[]];
            var label=[];
            var data1=[];
            var data2=[];
            if(collections.length<=0)
            {return;}

            if ($scope.filtername=="" && $scope.filterdept=="" )
            {
                $scope.getdept();
                return;
            }
            var cc=$filter('filter')(collections,{'Spe_name':$scope.filtername});
            $scope.collections= $filter('filter')(cc,{'Dept_name':$scope.filterdept})
            angular.forEach($scope.collections,function (data) {
                label.push(data.Spe_name);
                data1.push(data.Spec_havenum);
                data2.push(data.Spec_regnum);
            });
            $scope.labels = label;
            $scope.data = [
                data1,
                data2
            ];
            console.log(label);
            console.log(data1,data2);
            console.log($scope.data);
        }
        $scope.getdept=function () {
            $scope.data=[[],[]];
            $scope.filtername="";
            $scope.isLoading=true
            getdataservice.all('/Special/Index/v='+new Date().getTime()).then(function (data) {
                var label=[];
                var data1=[];
                var data2=[];
                collections=data.Data;
                $scope.collections=collections;

                $scope.isLoading=false;
                angular.forEach($scope.collections,function (data) {
                    label.push(data.Spe_name);
                    data1.push(data.Spec_havenum);
                    data2.push(data.Spec_regnum);
                });

                $scope.labels = label;

                $scope.series = ['实报', '应报'];


                $scope.data = [
                    data1,
                    data2
                ];
                $scope.colors= ['#ff6384', '#00ADF9'];

            },function () {
                $scope.isLoading=false;
            })
        }


    }
})();